package com.server.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.server.authority.Login;
import com.server.common.base.ProjectInfor;
import com.server.common.base.SessionData;
import com.server.service.ICommonDataService;
import com.server.service.IMngUserService;
import com.server.web.DataVector;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;
import com.server.web.RequestInput;
import com.server.web.SessionUtil;

@Controller("UserMngController")
@RequestMapping("userMng")
public class UserMngController {
private String tableName = "education.user";
	
	@Autowired
	private IMngUserService mngUserService;
	@Autowired
	private ICommonDataService commonDataService;
	
	@Login
	@RequestMapping("/{type}")
	public ModelAndView user(HttpServletRequest request,HttpServletResponse response,
			@PathVariable Integer type){
		ModelAndView mv = new ModelAndView("user/userList");
		mv.addObject("rootPath", ProjectInfor.ROOT_PATH);
		mv.addObject("type", type);
		return mv;
	}
	@Login
	@RequestMapping("list")
	public void list(HttpServletRequest request,
			HttpServletResponse response) {
		String _whereStr = "valid=1";
		String sortStr = "createTime desc";
		DataVector<Map<String, Object>> listData = commonDataService.getListData(tableName, _whereStr, sortStr, new RequestInput(request));
		OutputUtil.returnGridData(response, listData.getCount(), JSONSerielizer.toJson(listData.getList(), null, null));
	}
	@Login
	@RequestMapping("form/{id}")
	public void form(HttpServletRequest request,
			HttpServletResponse response,@PathVariable String id){
		Map<String, Object> formData = commonDataService.getFormData(tableName, "id", id, null, null);
		OutputUtil.returnString(response, JSONSerielizer.toJson(formData, null, null));
	}
	@Login
	@RequestMapping("check/{id}/{state}/{type}")
	public ModelAndView check(HttpServletRequest request,
			HttpServletResponse response,@PathVariable Integer id,
			@PathVariable Integer state,@PathVariable Integer type) {
		String userName = SessionUtil.getStringAttri(request, SessionData.nameKey_mng);
		ModelAndView mv = new ModelAndView("/common/editFrame");
		mv.addObject("pagePath","pages/user/userForm.jsp");
		mv.addObject("rootPath",ProjectInfor.ROOT_PATH);
		mv.addObject("action", "check");
		mv.addObject("state", state);
		mv.addObject("type", type);
		mv.addObject("business", "userMng");
		mv.addObject("titleName", "查看注册用户信息");
		mv.addObject("userName", userName);
		return mv;
	}
}
